﻿<%@ WebHandler Language="C#" Class="Ajax_register" %>

using System;
using System.Web;
using BackboneTest.BLL;
using BackboneTest.Models;
using Newtonsoft.Json;

public class Ajax_register : IHttpHandler {
    TB_UserBLL bll = new TB_UserBLL();
    TB_User model = new TB_User();
    public void ProcessRequest (HttpContext context) {
        //context.Response.ContentType = "text/plain";
      context.Response.ContentType = "application/json";

      //  int i = context.Request.Form.Count;
      //i = context.Request.QueryString.Count;



      //if (context.Request.Params.Count > 0)
      //{
      //    model.UserName = context.Request.Params["UserName"].ToString();
      //    model.LoginID = context.Request.Params["LoginID"].ToString();
      //    model.PWD = context.Request.Params["PWD"].ToString();
      //    model.Company = context.Request.Params["Company"].ToString();
      //    model.Email = context.Request.Params["Email"].ToString();
      //}
      //context.Response.Write(Register(model));

        //string test = context.Request.InputStream.ToString();
      //context.Response.Write(test);

      //读取 POST request-body 内容的方法  

      string httpMethod = context.Request.HttpMethod;
        
      #region 
     
      string method = string.Empty;
      byte[] aa = new byte[context.Request.ContentLength];
      string ss = "";
      try
      {
          int r = context.Request.InputStream.Read(aa, 0, context.Request.ContentLength);
      }
      catch (Exception ex)
      {
          ss = ex.Message;
      }
      ss = System.Text.Encoding.UTF8.GetString(aa);
        
      #endregion
        
      model = JsonConvert.DeserializeObject<TB_User>(ss);  
      context.Response.Write(Register(model));
     // context.Response.Write(ss ?? "bbbb");
      return;
        
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

    public string Register(TB_User model)

    {
        string json = JsonConvert.SerializeObject(bll.Register(model));

        return json;
    }

}